package com.cn.genericity.maxargs;

import com.cn.genericity.person.Person;

import java.util.Comparator;

/**
 * @author hels
 * @version 1.0
 * @date 2022/12/13 16:33
 * 在静态方法中使用泛型，需要注意在语法：static<泛型>
 */
class Args01 {

    public static<T extends Comparable<T>> T findMax(T[] arr) {
        T max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max.compareTo(arr[i]) < 0) {
                max = arr[i];
            }
        }
        return max;
    }
}

class People implements Comparable<People> {
    public int num;

    public People(int num) {
        this.num = num;
    }

    @Override
    public int compareTo(People p) {
        return this.num - p.num;
    }
}

public class Test01 {
    public static void main(String[] args) {
        People[] pps = {new People(2), new People(4), new People(9)};
        System.out.println(Args01.findMax(pps).num);
    }
}
